
var pnum = "";   
var initData = function(num){
       var param = {
           page_num:num,
           page_size:"10"
       }
		$.ajax({
	        url: base + "/dataCenter/businessdata/findDesignMajorData",
	        data: param,
	        success: function (data, textStatus, jqXHR) {
	        	var pageCount = data.pager.pageCount;
	        	var dataObj ={
	        			"list":data.list,
	         			"dataTool":{
	         				"title":{
	          			      	"project_design_major_code": "设计专业代码"
	          			      	,"project_design_major_name": "设计专业名称"
	          			      	,"serial_number":"排序规则"
	          			      	,"create_time":"创建时间"
	          			      	,"update_time":"修改时间"
	          			      	,"operation":"操作"
	            			},
	            			"titleCheckbox":false,
							"btn":[{"event":"updateObj","name":"编辑"},
							       {"event":"delObj","name":"删除"}]
						}
		  		};
	        	showPageTable('view', dataObj,num,pageCount,"initData");
	        },
	        error: function () {
	        }
	    });
   }

   var searchObj = function (num) {
	   if (num==undefined|| num==""||num.type=="click" ) {
           num=1;
	   }
       var name=$("#searchName").val();
       var param = {
           page_num:num,
           page_size:"10",
           name:name
       }
       $.ajax({
           url: base + "/dataCenter/businessdata/findDesignMajorData",
           data: param,
           success: function (data, textStatus, jqXHR) {
               debugger
               var pageCount = data.pager.pageCount;
               var dataObj ={
                   "list":data.list,
                   "dataTool":{
                       "title":{
                           "project_design_major_code": "设计专业代码"
                           ,"project_design_major_name": "设计专业名称"
                           ,"serial_number":"排序规则"
                           ,"create_time":"创建时间"
                           ,"update_time":"修改时间"
                           ,"operation":"操作"
                       },
                       "titleCheckbox":false,
                       "btn":[{"event":"updateObj","name":"编辑"},
                           {"event":"delObj","name":"删除"}]
                   }
               };
               showPageTable('view', dataObj,num,pageCount,"searchObj");
           },
           error: function () {
           }
       });
   }

   var delObj = function(obj){
	   layer.confirm('确认删除?',{btn : [ '确定', '取消' ]},function(index){
		   layer.close(index);
		   var param = {id:obj.id}
		   $.ajax({
			   url:base+"/dataCenter/businessdata/delDesignMajorById",
			   data:param,
			   success:function(data,status){
				    if(data.statusCode == 0){
						layer.msg(data.message, {
							icon : 1
						});
				    }else{
						layer.msg(data.message, {
							icon : 5
						});
				    }
				    initData(pnum);
			   }
		   });
	   });
   }
    
   var updateObj = function(obj){
		var contentDiv = function(){
			var content;
			var data={
					"title":{
						    "id":"唯一标识",
		        			"major_code":"专业代码",
					      	"major_name": "专业名称",
					      	"serial_number":"排序规则"
					},"text":{
						    "id":obj.id==null?"":obj.id
						    ,"major_code":obj.project_design_major_code==null?"":obj.project_design_major_code
							,"major_name":obj.project_design_major_name==null?"":obj.project_design_major_name
							,"serial_number":obj.serial_number==null?"":obj.serial_number
					},"input":{
						    "id":"hidden"
						    ,"major_code":"text"
							,"major_name":"text"
							,"serial_number":"text"
					},"input_init":{
						
					}
			};
			var getDiv =  dc_update.innerHTML;
			laytpl(getDiv).render(data, function(html){
				content = html;
			}); 
			return content;
		}
		layer.open({
			  	title:'更新设计专业'
				,content: contentDiv()
		    	,area: ['800px', '400px']
		        ,scrollbar: false
			  	,btn: ['确认', '取消']
				,yes: function(index,layero){ //确认
					var data = $(layero).find("form").serializeJSON();
					if(data.major_code == ""){
						var obj = $("input[name='major_code']");
						obj.focus();
						layer.tips('请填写此字段!', obj);
						return false;
					}
					if(data.serial_number == ""){
						var obj = $("input[name='serial_number']");
						obj.focus();
						layer.tips('请填写此字段!', obj);
						return false;
					}
					if(data.major_name == ""){
						var obj = $("input[name='major_name']");
						obj.focus();
						layer.tips('请填写此字段!', obj);
						return false;
					}
					$.post(base+"/dataCenter/businessdata/updateDesignMajor",{
						id:data.id,
						project_design_major_code:$.trim(data.major_code),
						project_design_major_name:$.trim(data.major_name),
						serial_number:$.trim(data.serial_number)
					},
			  		function (data,status){
						if(data!=""&&data!=null){
							if(data.statusCode == 0){
								layer.msg('更新成功', {icon: 1,time:2000});
							}else{
								layer.msg(data.message, {icon: 2,time:2000});
							}
						}else{
							layer.msg('更新失败!', {icon: 2,time:2000});
						}
						initData(pnum);
			  		 })
				}
		});
   }

   $(document).ready(function(){
	   initData(1);
	   $("#addData").click(updateObj);
       $("#searchInfo").click(searchObj);
   });